package com.example.demo01minio;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo01minio.domain.Emp;
import com.example.demo01minio.mapper.EmpMapper;
import com.example.demo01minio.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * ClassName:MPTest2
 * Package:com.example.demo01minio
 * Description:
 *
 * @Author:helei
 * @Create:2024/8/28 - 8:41
 */
@SpringBootTest
public class MPTest2 {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private UserService userService;

    @Test
    void test3(){
        userService.getById(1);
        //有id表示更新，没有id表示新增
//        userService.saveOrUpdate();
    }

    /**
     * 自定义
     */
    @Test
    void test2() {
//        List<Emp> list = empMapper.selectBetweenSalary(20000, 50000);
        QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("emp_salary", 50000);
        queryWrapper.ge("emp_salary", 20000);
        queryWrapper.orderByAsc("emp_salary");
//        List<Emp> list = empMapper.selectBetweenSalaryByWrapper(queryWrapper);

        Page<Emp> page = new Page<>(1, 3);
        List<Emp> list = empMapper.selectPageBetweenSalaryByWrapper(page, queryWrapper);
        //组装分页数据
        page.setRecords(list);
        System.out.println("page.getPages() = " + page.getPages());
        page.getRecords().forEach(System.out::println);
    }

    @Test
    void test1() {
        LambdaQueryWrapper<Emp> wrapper = new LambdaQueryWrapper<>();
        wrapper.gt(Emp::getEmpSalary, 20000); //大于等于
        wrapper.le(Emp::getEmpId, 10); //小于等于
        empMapper.selectPage(new Page<Emp>(2, 3), wrapper);
    }


}
